import pygame, random
IMAGE_PATH = "D:\\MyLinux\\Ubuntu\\Sharedfiles\\6temp\\python-learning\\Airplanewar\\res\\"

# 自定义敌机类
class EnemyPlane(object):

    def __init__(self, mapWidth = 512, mapHeight = 768):
        self.mapWidth = mapWidth
        self.mapHeight = mapHeight
        self.num = str(random.randint(1, 7)) 
        self.img = pygame.image.load(IMAGE_PATH + "img-plane_" + self.num + ".png") # 图片
        self.img_rect = self.img.get_rect() # 获取敌机的图片矩形
        self.reset()

    # 设置敌机的位置和速度
    def reset(self):
        self.img_rect[0] = random.randint(0, self.mapWidth - self.img_rect[2]) 
        self.img_rect[1] = -self.img_rect[3]
        self.speed = random.randint(3, 5) # 速度

    # 向下移动
    def move_down(self):
        self.img_rect.move_ip(0, self.speed)
        # 判断如果在屏幕消失后 位置重置
        if self.img_rect[1] >= self.mapHeight:
            self.reset()



